const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});

const db=cloud.database();

exports.main = async (event, context) => {
  const {account,Class,name,college,gender,grade}=event.data;
  try{
    const repeat=await db.collection("student").where(
      {
        account:account
      }
    ).get();
    if(repeat.data.length==1){
      try{
        const up=await db.collection("student").where({
          account:account
        }).update({
          data:{
            Class:Class,
            name:name,
            college:college,
            gender:gender,
            grade:grade
          }
        })
          return {success:true,message:"修改成功"}
      }catch(error){
          console.error(error);
          return{success:false,message:"0"+error+"  class="+Class}
      }
    }
    else{
      return {success:false,message:"修改失败"}
    }
  }catch(error){
    return{success:false,message:"1"}
  }
};